package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.server.mapper.BlackListMapper;
import com.tanhua.server.pojo.BlackList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021/3/3 21:00
 * @version: 0.0.1
 * @modified By:
 */
@Service
public class BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;
    
    public IPage<BlackList>queryList(Long userId,Integer page,Integer pageSize){
        QueryWrapper<BlackList>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        //排序，根据创建时间倒序排序
        queryWrapper.orderByDesc("created");
        IPage<BlackList> blackListIPage = this.blackListMapper.selectPage(new Page<>(page, pageSize), queryWrapper);
        return blackListIPage;
    }

    public Boolean deleteBlackById(Long userId, Long blackUserId) {
        QueryWrapper<BlackList>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).eq("black_user_id",blackUserId);
        return this.blackListMapper.delete(queryWrapper)>0;
    }
}
